const { app, Menu, ipcMain } = require('electron')

//监听ipcRenderer发送的数据
app.on('ready', () => {

    let socket = null

    let timeSteam = null

    let window = require('./window')

    window.loadFile('./resource/index.html')

    ipcMain.on('open', (e, data) => {
        if(!socket){
            socket = require('./socket')(data)
            socket.on('open', (data) => {
                if (timeSteam != null) {
                    clearTimeout(timeSteam)
                    timeSteam = null
                }
                window.webContents.send('open', data || true)
            })

            timeSteam = setTimeout(() => {
                socket.close()
                socket = null
                window.webContents.send('open', false)
            }, 5000)
        }
    })

    // window.webContents.openDevTools()

    Menu.setApplicationMenu(null)

})